#ifndef TABLE_H
#define TABLE_H

#include "schemacomponent.h"
#include "enums.h"
#include "tableconstraintlist.h"
#include <string>

using namespace std;

// forward declarations
class TableColumnList;
class TableColumn;
class TableConstraint;
class SchemaComponentFormula;

/*
    Class: Table
    Represents an SQL Table.
*/
class Table : public SchemaComponent
{
    /* Section: public */
    public:
        /*
            Constructor: Default constructor
            Initializes the object.

            Parameters:
                name - Name of the table ("" by default).
                rows - Number of rows of the table (1 by default).

            See also:
                AbstractTable.
        */
        Table(TableColumnList * columns = NULL, TableConstraintList * constraints = NULL, const string & name = "", int rows = 1);

        /*
            Destructor: Default destructor
            Destroy the object.
        */
        virtual ~Table();

        /*
            Constructor: Copy constructor
            Initializes the object as a copy of other Table object.

            Parameters:
                other - Table to copy from.
         */
        Table(const Table& other);

        /*
            Method: SetColumns
            Sets the columns of the table. Destroy the previous columns if any.

            Parameters:
                columns - List of columns to set.

            See also:
                TableColumnList
        */
        void setColumns(TableColumnList * columns);

        /*
            Method: SetConstraints
            Sets the constraints defined over the table.

            Parameters:
                constraints - List of constraints.

            See also:
                TableConstraintList
        */
        void setConstraints(TableConstraintList * constraints);

        /*
            Method: getTableColumns
            Returns:
                The columns of the Table.
        */
        TableColumnList * getTableColumns() const;

        /*
            Method: GetConstraints
            Returns:
                The constraints over the table.
        */
        TableConstraintList * getConstraints() const;

        /*
            Method: AddColumn
            Add a column to the list of columns of the table.

            Parameters:
                column - Column to add.

            See also:
                TableColumn
        */
        void addColumn(TableColumn * column);

        /*
            Method: addColumn
            Add a column woth the name and types given.

            Parameters:
                name    -   Name of the column
                type    -   Type of the column.
        */
        void addColumn(const string & name, TableColumnType type);

        /*
            Method: AddConstraint
            Add a constraint to the list of constraints of the table.

            Parameters:
                constraint - Constraint to add.

            See also:
                TableConstraint.
        */
        void addConstraint(TableConstraint * constraint);

        /*
            Method: ToString

            See also:
                AbstractTable.
        */
        virtual string toString();

        /*
            Method: SetRows
            Sets the number of rows of the table.

            Parameters:
                rows - Number of rows to set.
        */
        void setRows(int rows);

        /*
            Method: GetRows

            See also:
                AbstractTable
        */
        int getRows();
    

	/*Method getColumns
	 * Returns:
	 * 	The list of the names of the columns
	 */
	virtual ColumnList* getColumns();

        /*
            Method: Clone
            Returns:
                A pointer to clone of this object.
        */

        virtual SchemaComponent * clone();

        /*
            Method: GetColumnType

            Parameters:
                name -  Column name to get it's type.

            Returns:
                The Type of the Column name given,.
        */
        TableColumnType getColumnType(const string & name);

    /* Section: private */
    private:
        /*
            Variable: columns.
            Type: TableColumnList
            Columns of the table.
        */
        TableColumnList * columns;

        /*
            Variable: constraints.
            Type: ConstraintList
            Default constraints of the table.
        */
        TableConstraintList * constraints;

        /*
            Variable: rows
            Type: int
            Number of rows of the table.
        */
        int rows;
};

#endif // TABLE_H
